#include <atcoder/convolution>
#include <atcoder/modint>
#include <bits/stdc++.h>

using namespace std;
using namespace atcoder;
using mint = modint998244353;

const int MAXN = 5e5 + 5;
mint fac[MAXN], inv[MAXN];
int n, m, a[MAXN], b[MAXN];

int main() {
  fac[0] = 1;
  for (int i = 1; i < MAXN; ++i)
    fac[i] = fac[i - 1] * i;
  inv[MAXN - 1] = 1 / fac[MAXN - 1];
  for (int i = MAXN - 2; i >= 0; --i)
    inv[i] = inv[i + 1] * (i + 1);

  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i)
    scanf("%d", a + i);
  for (int i = 1; i <= m; ++i)
    scanf("%d", b + i);

  vector<mint> x, y;
  x.resize(MAXN);
  y.resize(MAXN);
  for (int i = 1; i <= m; ++i)
    x[b[i]] += inv[b[i]];
  for (int i = 0; i < MAXN; ++i)
    y[i] = inv[i];

  auto z = convolution(x, y);

  mint ans = 0;
  for (int i = 1; i <= n; ++i) {
    ans += fac[a[i]] * z[a[i]];
  }
  printf("%d\n", ans.val());
  return 0;
}
